<template>
  <div class="home-container">
    <el-row :gutter="20">
      <el-col :span="8">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>学生总数</span>
            </div>
          </template>
          <div class="card-content">
            <el-statistic :value="studentCount">
              <template #title>
                <div style="display: inline-flex; align-items: center">
                  学生
                  <el-icon style="margin-left: 4px">
                    <User />
                  </el-icon>
                </div>
              </template>
            </el-statistic>
          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>课程总数</span>
            </div>
          </template>
          <div class="card-content">
            <el-statistic :value="courseCount">
              <template #title>
                <div style="display: inline-flex; align-items: center">
                  课程
                  <el-icon style="margin-left: 4px">
                    <Reading />
                  </el-icon>
                </div>
              </template>
            </el-statistic>
          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>平均成绩</span>
            </div>
          </template>
          <div class="card-content">
            <el-statistic :value="averageGrade" :precision="2">
              <template #title>
                <div style="display: inline-flex; align-items: center">
                  成绩
                  <el-icon style="margin-left: 4px">
                    <DataAnalysis />
                  </el-icon>
                </div>
              </template>
            </el-statistic>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" style="margin-top: 20px">
      <el-col :span="24">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>最近活动</span>
            </div>
          </template>
          <div class="card-content">
            <el-timeline>
              <el-timeline-item
                v-for="(activity, index) in activities"
                :key="index"
                :timestamp="activity.timestamp"
                :type="activity.type"
              >
                {{ activity.content }}
              </el-timeline-item>
            </el-timeline>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { User, Reading, DataAnalysis } from '@element-plus/icons-vue';

// 模拟数据
const studentCount = ref(256);
const courseCount = ref(32);
const averageGrade = ref(85.6);

const activities = ref([
  {
    content: '添加了新学生：张三',
    timestamp: '2023-10-15 14:30',
    type: 'primary',
  },
  {
    content: '更新了课程：高等数学',
    timestamp: '2023-10-14 10:15',
    type: 'success',
  },
  {
    content: '录入了期中考试成绩',
    timestamp: '2023-10-12 16:45',
    type: 'warning',
  },
  {
    content: '添加了新课程：大学物理',
    timestamp: '2023-10-10 09:20',
    type: 'info',
  },
]);
</script>

<style scoped>
.home-container {
  padding: 20px;
}

.box-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-content {
  padding: 10px 0;
}
</style>